import { request } from "@/utils/request"
import { GET_ARTICLE_LIST, GET_CHANNEL_LIST } from "../constants"

export const getChannelList = () => {
  return async dispatch => {
    const res = await request.get('/channels')
    // console.log(res.data.data.channels)
    const channels = res.data.data.channels
    dispatch({
      type: GET_CHANNEL_LIST,
      payload: channels
    })
  }
}

// 获取文章列表
export const getArticleList = (params) => {
  return async dispatch => {
    const res = await request.get('/mp/articles', { params })
    // console.log(res)
    dispatch({
      type: GET_ARTICLE_LIST,
      payload: res.data.data
    })
  }
}

export const delArticle = (id) => {
  return async (dispatch) => {
    await request.delete(`/mp/articles/${id}`)
  }
}